#pragma once

#include "d3dApp.h"
#include <vector>
#include "SearchCell.h"
#include "Level.h"
#include "d3dutil.h"
#include "LevelElement.h"
#include "Vertex.h"

using namespace std;

class EmptyApp;

#define CELLSIZE 3

class PathFinding
{
public:
	PathFinding(Level* level);
	~PathFinding(void);

	void FindPath(D3DXVECTOR3 currentPos, D3DXVECTOR3 targetPos);
	NxVec3 NextPathPos(LevelElement &Army);
	void ClearOpenList() { m_openList.clear(); }
	void ClearVisitedList() { m_VisitedList.clear(); }
	void ClearPathToGoal() { m_pathToGoal.clear(); }
	bool m_initializedStartGoal;
	bool m_foundGoal;
	vector<D3DXVECTOR3*> GetPath(){return m_pathToGoal;}

private:
	void setStartAndGoal(SearchCell start, SearchCell goal);
	void Pathopened(int x, int z, float newCost, SearchCell *parent);
	SearchCell * GetNextCell();
	void ContinuePath();

	SearchCell * m_StartCell;
	SearchCell * m_GoalCell;
	Level* m_pLevel;
	
	std::vector<SearchCell*> m_openList;
	std::vector<SearchCell*> m_VisitedList;
	std::vector<D3DXVECTOR3*> m_pathToGoal;
};